<script>
	import {clearAutoLoginTimes} from '@/static/js/common.js';
	// import Vue from 'vue'
	import { getCurrentInstance } from 'vue';
	export default {
		onLaunch: function() {
			clearAutoLoginTimes();
			uni.getSystemInfo({
				success: function(e) {
					// #ifndef MP
					const app = getCurrentInstance();
					app.prototype.globalData.StatusBar = e.statusBarHeight;
					if (e.platform == 'android') {
						app.prototype.globalData.CustomBar = e.statusBarHeight + 50;
					} else {
						app.prototype.globalData.CustomBar = e.statusBarHeight + 45;
					}
					// #endif
				}
			})
			// #ifdef H5
			if (this.globalData.debug) {
				// this.globalData.url = 'https://zst.om909.com/';
				// this.globalData.url = 'http://192.168.11.111/';
				this.globalData.url = 'http://192.168.11.154/';
			} else {
				this.globalData.url = window.location.origin + '/';
			}
			// #endif
			// #ifdef APP-PLUS
			let _that = this;

			if (!this.globalData.url) {
				let orgSite = uni.getStorageSync('ORG_SITE')
				if (orgSite) {
					if (orgSite.site) {
						if (orgSite.site.endsWith('/')) {
							_that.globalData.url = orgSite.site
						} else {
							_that.globalData.url = orgSite.site + '/'
						}
					} else {
						_that.globalData.url = orgSite
					}
				}
			}

			plus.push.getClientInfoAsync((info) => {
				let cid = info["clientid"];
				uni.setStorageSync("clientid", cid.toString())

				// uni.request({
				//   method: 'POST',
				//   url: 'https://6f967b78-7561-4a28-8871-b077b392ba82.bspapp.com/getPlshInfo',
				//   data: {
				//     clientid: cid.toString(),
				//     title: '标题zz',
				// 	content: '内容zz',
				// 	payload: JSON.stringify({type:1,num:12}),
				//   },
				//   success(res) {

				//   }
				// })
			})
			// var payload = {"authKey":"cab80926ac2d2281803aecec6149365cb0f8c8b334178d1cf3329efdf344c4df","orgName":"星际控股集团有限公司","busCode":"HRS1201","orgSite":"http://192.168.11.43/","mobile":"13676773366","fileCode":"jjd2309160001","orgId":1,"fileId":30435};
			// var msg = {"clientId":"73eea229fe9548d19d4a969ffab2801e","content":"戴永鑫请假(编码:jjd2309160001),需要您发送","fileId":30435,"formCode":"HRS1201","title":"待办","userId":2,"userName":"戴永鑫"};
			// msg.payload = JSON.stringify(payload);
			// _that.globalData.setData(msg);
			
			plus.push.addEventListener('click', function(msg) {
				var pushMsg = '';
				if(typeof msg === 'string'){
					pushMsg = msg;
				}else{
					pushMsg = JSON.stringify(msg);
				}
				uni.setStorageSync('payloadData2', pushMsg);
			}, false);
			
			
			plus.push.addEventListener("receive", function(msg) {
				// if (msg.aps) { // Apple APNS message  
				//    //APNS下发的消息，应用在前台  
				//     plus.push.createMessage(msg.content, msg.payload, {
				//         title: msg.title
				//     });
				// } else if (msg.type != "receive") { // 特殊payload标识本地创建的消息    
				//     //本地创建的消息，通常不需要处理     
				//     //注意：不要在这种情况下再此调用plus.push.createMessage，从而引起循环创建本地消息    
				// } else {
				//     //接收到在线透传消息  
				//     plus.push.createMessage(msg.content, msg.payload, {
				// 		title: msg.title
				//     });
				// }
				if (msg.type == "receive"){ // 防循环推送。 
					uni.createPushMessage({
						title: msg.title,
						content: msg.content,
						payload: msg.payload,
					})
					let obj = JSON.parse(msg.payload)
					let num = parseInt(obj.num)
					//仅支持ios
					// uniPush.setBadgeByCid({
					// 	"cid":"xxx",
					// 	"badge": "-8"
					// })
					//支持ios华为小米
					plus.runtime.setBadgeNumber(num)
				}	   	
			}, false);

			// uni.onPushMessage((res) => {
			// 	uni.createPushMessage({
			// 		title: res.data.title,
			// 		content: res.data.content,
			// 		payload: res.data.payload,
			// 	})
			// 	let obj = JSON.parse(res.data.payload)
			// 	let num = parseInt(obj.num)
			// 	//仅支持ios
			// 	// uniPush.setBadgeByCid({
			// 	// 	"cid":"xxx",
			// 	// 	"badge": "-8"
			// 	// })
			// 	//支持ios华为小米
			// 	plus.runtime.setBadgeNumber(num)
			// })
			// #endif
		},
		globalData: {
			url: '',
			// #ifdef APP || APP-PLUS || APP-NVUE || APP-PLUS-NVUE || APP-VUE
			omMateServer: 'http://139.9.158.175:82/',
			// omMateServer: 'http://192.168.11.253:82/',
			// omMateServer: 'http://192.168.11.101:82/',
			// omMateServer: 'http://192.168.6.66:82/',
			setData(msg) {
				var pushMsg = '';
				if(typeof msg === 'string'){
					pushMsg = msg;
				}else{
					pushMsg = JSON.stringify(msg);
				}
				uni.setStorageSync('payloadData2', pushMsg);
				var pushMsgObj = JSON.parse(pushMsg);
				var payload = null;
				if(typeof pushMsgObj.payload === 'string'){
					payload = JSON.parse(pushMsgObj.payload)
				} else {
					payload = pushMsgObj.payload;
				}
				var orgSite = {
					site: payload.orgSite,
					name: payload.orgName
				};
				uni.setStorageSync('ORG_SITE', orgSite);
			},
			// #endif
			debug:true,
			pageNum: 20,
			button: {
				top: {
					text: '返回顶部',
					iconPath: '/static/images/others/top.png'
				},
				home: {
					text: '返回首页',
					iconPath: '/static/images/tabbar/homeHL.png'
				},
				read: {
					text: '全部已读',
					iconPath: '/static/images/others/over.png'
				}
			},
			icon: {
				going: 'static/images/others/going.png', //未完成的表单图标
				over: 'static/images/others/over.png', //审批通过的表单图标
				unapprove: 'static/images/others/unapprove.png' //审批未通过的表单图标
			}
		},
		uploadUrl:'uploadFileData/uploadInterimFile',
		loadUrl:'uploadFileData/getInterimFile',
	};
</script>

<style>
	/* #ifndef APP-PLUS-NVUE */
	@import '/static/css/common.css';
	@import '/static/css/thorui/thorui.css';
	@import '/static/css/other.css';
	@import '/colorui/main.css';
	@import '/colorui/icon.css';
	/* #endif */
</style>
